package com.zdl.mysmall.testservice

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.zdl.mysmall.testservice.service.BackGroundService
import kotlinx.android.synthetic.main.activity_main.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import kotlin.concurrent.thread
import android.support.v4.app.SupportActivity
import android.support.v4.app.SupportActivity.ExtraData
import android.support.v4.content.ContextCompat.getSystemService
import android.icu.lang.UCharacter.GraphemeClusterBreak.T




class MainActivity : AppCompatActivity() {

    var aa = 0

    val  handler = Handler(){
        aa++
        tv_1.text = aa.toString()
        return@Handler true
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val forgroundService = Intent(this, BackGroundService::class.java)
        startService(forgroundService)
        tv_1.text = "0"
        EventBus.getDefault().register(this)

        thread {

            while (true) {
                Thread.sleep(20000)
                handler.sendEmptyMessage(2)
            }



        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onGetMessage(message: MessageWrap) {
        Log.e("tag", "asdad")
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }
}
